import { useSettingsStore } from '@/store/modules/settings'
import { useUserStore } from '@/store/modules/user'
import useMediaQuery from './useMediaQuery'
const { isDesktop } = useMediaQuery()

/**
 * 初始化登录用户个人信息
 */
export const useInitUserData = () => {
  const userStore = useUserStore()
  if (userStore.token) {
    userStore.initUserData()
  }
}

/**
 * 媒体查询当前屏幕大小 从而响应式
 */
export const useWatchMediaQuery = () => {
  const settingsStore = useSettingsStore()

  watch(isDesktop, (newData) => {
    settingsStore.sidebar.opened = newData
    settingsStore.sidebar.isfixed = !newData  // 因为手机大小才会固定 所以需要取反

    settingsStore.navbar.showBreadcrumb = newData
    settingsStore.navbar.showRefurbish = newData
  }, { immediate: true })
}